﻿<BadHabit_Factory_Controls:TaskViewerBase
    x:Name="postItListBoxControl"
    x:Class="BadHabit.Factory.Controls.TaskPostItViewer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"           
    xmlns:BadHabit_Factory="clr-namespace:BadHabit.Factory"      
    xmlns:factoryCore="clr-namespace:BadHabit.Factory;assembly=BadHabit.FactoryCore"                                                                                                 
    xmlns:BadHabit_Factory_Controls="clr-namespace:BadHabit.Factory.Controls"   
    xmlns:BadHabit_Factory_Converters="clr-namespace:BadHabit.Factory.Converters"
    xmlns:BadHabit_WPFTools="clr-namespace:BadHabit.WPFTools;assembly=BadHabit.WPFTools" 
    xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"

    xmlns:props="clr-namespace:BadHabit.Factory.Windows.Properties"
    
    xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
    
    Loaded="UserControl_Loaded"
    
    DataContextChanged="TaskViewerBase_DataContextChanged"
    >



    <BadHabit_Factory_Controls:TaskViewerBase.CommandBindings>        
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.ViewTaskTail" Executed="ViewTaskTailCommandBinding_Executed" />        
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.CancelTask" Executed="CancelTaskCommandBinding_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.DoneTask" Executed="DoneTaskCommandBinding_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.UnitChangeTask" Executed="UnitChangeTaskCommandBinding_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.IsPayableChangeTask" Executed="IsPayableChangeTaskCommandBinding_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.MoveTask" Executed="MoveTaskCommandBinding_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.AddTaskMaterial" Executed="AddTaskMaterial_Executed" />
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.AddTaskMaterialLink" Executed="AddTaskMaterialLink_Executed" />
    </BadHabit_Factory_Controls:TaskViewerBase.CommandBindings>

    <BadHabit_Factory_Controls:TaskViewerBase.Resources>

        <BadHabit_Factory_Converters:IsReadOnlyTaskConverter x:Key="IsReadOnlyTaskConverter"/>

        <Control x:Key="PanDownCursorMock" Cursor="/Images/Cursors/PanDown.cur" />
        <Control x:Key="PanCursorMock" Cursor="/Images/Cursors/Pan.cur" />

        <DataTemplate x:Key="PostItTemplate">
            <Grid x:Name="postItGrid">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Border x:Name="postItBorder"
                        Grid.Row="0"
                    
                    
                    
                    Margin="2,0,2,0"
                    Loaded="postItBorder_Loaded"                    
                    Width="120"
                    Height="110"             
                    SnapsToDevicePixels="True"
                    Cursor="/Images/Cursors/Pan.cur"
                    MouseLeftButtonDown="postItBorder_MouseDown"
                    MouseLeftButtonUp="postItBorder_MouseUp"
                    DragDrop.GiveFeedback="postItBorder_GiveFeedback"                                                            
                    ToolTip="{StaticResource TaskToolTip}"                    
                    ContextMenu="{StaticResource TaskContextMenu}">
                    <Border.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=TaskType}" Value="0">
                                    <Setter Property="Border.Background">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="/Images/postIt.gif" Stretch="Fill"/>
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Path=TaskType}" Value="1">
                                    <Setter Property="Border.Background">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="/Images/postIt.gif" Stretch="Fill"/>
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Path=TaskType}" Value="2">
                                    <Setter Property="Border.Background">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="/Images/postIt.gif" Stretch="Fill"/>
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Path=TaskType}" Value="3">
                                    <Setter Property="Border.Background">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="/Images/postIt.gif" Stretch="Fill"/>
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Path=TaskType}" Value="4">
                                    <Setter Property="Border.Background">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="/Images/postItImpediment.gif" Stretch="Fill"/>
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>


                            </Style.Triggers>
                        </Style>
                    </Border.Style>
                    <Border.Triggers>
                        <EventTrigger SourceName="taskNameTextBox" RoutedEvent="TextBox.GotFocus">
                            <EventTrigger.Actions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation
                                            BeginTime="0:0:0.2"
                                            Storyboard.TargetName="postItBorder"
                                            Storyboard.TargetProperty="Width"
                                            To="148"
                                            Duration="0:0:0.1"
                                            PresentationOptions:Freeze="True"/>
                                        <DoubleAnimation
                                            BeginTime="0:0:0.2"
                                            Storyboard.TargetName="postItBorder"
                                            Storyboard.TargetProperty="Height"
                                            To="136"
                                            Duration="0:0:0.1"
                                            PresentationOptions:Freeze="True"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger.Actions>
                        </EventTrigger>
                        <EventTrigger SourceName="taskNameTextBox" RoutedEvent="TextBox.LostFocus">
                            <EventTrigger.Actions>
                                <BeginStoryboard>
                                    <Storyboard>

                                        <DoubleAnimation
                                            BeginTime="0:0:0.2"
                                            Storyboard.TargetName="postItBorder"
                                            Storyboard.TargetProperty="Width"
                                            To="120"
                                            Duration="0:0:0.1"
                                            PresentationOptions:Freeze="True"/>
                                        <DoubleAnimation
                                            BeginTime="0:0:0.2"
                                            Storyboard.TargetName="postItBorder"
                                            Storyboard.TargetProperty="Height"
                                            To="110"
                                            Duration="0:0:0.1"
                                            PresentationOptions:Freeze="True"/>

                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger.Actions>
                        </EventTrigger>

                    </Border.Triggers>

                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>                      
                        </Grid.RowDefinitions>

                        <TextBox                                   
                                 x:Name="taskNameTextBox"
                        
                                 IsReadOnly="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}"
                        
                                 Grid.Row="0"                            
                                 Text="{Binding TaskName}" 
                                 SpellCheck.IsEnabled="True"                                 
                                 AcceptsReturn="True" TextWrapping="Wrap"
                                 FontSize="{StaticResource NeedToSeeFontSize}"
                                 MaxLength="100"        
                        
                                
                                 
                                 Background="Transparent" BorderThickness="0,0,0,0"
                                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                 Padding="0"
                                 Margin="2,2,20,2"/>



                        <BadHabit_WPFTools:ComboBox                                                                                        
                                Grid.Row="1"                                               
                                Style="{StaticResource TeamComboBox}"
                                ItemsSource="{Binding Source={StaticResource ProjectMemberList}}"                                                                                                            
                                BadHabit_WPFTools:RoleChecker.RequiredEnableRole="SCRUM_MASTER"
                                SelectionChanged="UpdateTaskUnitNameByMember"                                
                        />

                        <Grid Grid.Row="2" HorizontalAlignment="Stretch" Margin="0,0,3,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="2,0,0,0">
                                <Image Style="{StaticResource TaskIsLateAlertImage}" />
                                <Image DataContext="{Binding Status}" Style="{StaticResource TaskIsCanceledImage}" Width="16" Height="16" Stretch="Uniform" />
                                <Image DataContext="{Binding TaskType}" Style="{StaticResource TaskIsBugImage}"  Width="16" Height="16" Stretch="Uniform" />
                            </StackPanel>


                            <!--<Border Style="{StaticResource HighLightBorder}" Padding="0,0,0,0"  Margin="0,0,0,0"
                                Grid.Column="1"
                                ToolTip="Actual Effort">-->
                            <TextBox                             
                                Text="{Binding ActualEffort, StringFormat='{}{0:F1}', ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                                Grid.Column="1"
                                IsReadOnly="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}"
                                TextAlignment="Right"
                                FontSize="{StaticResource NeedToSeeFontSize}"
                                Background="Transparent" BorderThickness="0,0,0,0"                                                                                                
                                KeyUp="TextBox_KeyUp"
                                >
                                <TextBox.Style>
                                    <Style>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Status}" Value="1">
                                                <Setter Property="TextBox.IsEnabled" Value="False"/>
                                                <Setter Property="TextBox.Visibility" Value="Collapsed"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </TextBox.Style>
                            </TextBox>
                            <!--</Border>-->

                            <TextBlock Grid.Column="2" Text="/" FontSize="14"  />
                            <!--<Border Style="{StaticResource HighLightBorder}" Padding="0,0,0,0" Margin="0,0,0,0"
                                Grid.Column="3"
                                ToolTip="Planned Effort"
                                >-->
                            <TextBox 
                                Grid.Column="3"
                                Text="{Binding PlannedEffort, StringFormat='{}{0:F1}', ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                                IsReadOnly="{Binding ., Converter={StaticResource IsReadOnlyTaskConverter}}"
                                TextAlignment="Right"
                                FontSize="{StaticResource NeedToSeeFontSize}"
                                 Background="Transparent" BorderThickness="0,0,0,0"
                                KeyUp="TextBox_KeyUp"
                                 />
                            <!--</Border>-->




                        </Grid>

                      

                    </Grid>


                </Border>                
                <TextBlock x:Name="detailsLink" Grid.Row="1" Margin="0,0,0,0">
                    <Hyperlink Click="Hyperlink_Click">
                        <TextBlock Text="{x:Static props:Resources.Details}"/>
                    </Hyperlink>
                        <TextBlock.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=postItGrid,Path=IsMouseOver}"  Value="False">
                                        <Setter Property="TextBlock.Visibility" Value="Hidden"/>    
                                    </DataTrigger>                                                                          
                                                     
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                </TextBlock>
            </Grid>
     



        </DataTemplate>


    </BadHabit_Factory_Controls:TaskViewerBase.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ListBox
             x:Name="listBox"
             Grid.Row="0"
             ItemTemplate="{StaticResource PostItTemplate}"
             ItemsSource="{Binding}"             
             ScrollViewer.HorizontalScrollBarVisibility="Disabled"
             AllowDrop="True"
             Drop="listBox_Drop"
             SelectionMode="Single"         
             Padding="0,30,0,0"
             VerticalAlignment="Stretch"
             BorderThickness="0,0,0,0"                        
         >
            <ListBox.Style>
                <Style TargetType="ListBox">
                    <Setter Property="ItemsPanel">
                        <Setter.Value>
                            <ItemsPanelTemplate>
                                <WrapPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=postItListBoxControl, Path=TaskStatusFilter}">
                            <DataTrigger.Value>
                                <factoryCore:TaskStatus>TASK_REQUIRED</factoryCore:TaskStatus>
                            </DataTrigger.Value>
                            <Setter Property="ListBox.Background">
                                <Setter.Value>
                                    <ImageBrush ImageSource="{x:Static props:ImageResources.todo}" Stretch="None" TileMode="None" AlignmentX="Center" AlignmentY="Top" />
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ElementName=postItListBoxControl, Path=TaskStatusFilter}">
                            <DataTrigger.Value>
                                <factoryCore:TaskStatus>TASK_WORKINGON</factoryCore:TaskStatus>
                            </DataTrigger.Value>
                            <Setter Property="ListBox.Background">
                                <Setter.Value>
                                    <ImageBrush ImageSource="{x:Static props:ImageResources.working}" Stretch="None" TileMode="None" AlignmentX="Center" AlignmentY="Top" />
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ElementName=postItListBoxControl, Path=TaskStatusFilter}">
                            <DataTrigger.Value>
                                <factoryCore:TaskStatus>TASK_DONE</factoryCore:TaskStatus>
                            </DataTrigger.Value>
                            <Setter Property="ListBox.Background">
                                <Setter.Value>
                                    <ImageBrush ImageSource="{x:Static props:ImageResources.done}" Stretch="None" TileMode="None" AlignmentX="Center" AlignmentY="Top" />
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListBox.Style>

            <ListBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
            </ListBox.Resources>

            <ListBox.ContextMenu>
                <ContextMenu>
                    <ContextMenu.CommandBindings>                        
                        <CommandBinding Command="BadHabit_Factory:FactoryCommands.AddTask" Executed="AddTask_Executed"/>
                    </ContextMenu.CommandBindings>
                    <ContextMenu.Items>
                        <StaticResource ResourceKey="AddProjectTaskMenuItem"/>
                        <StaticResource ResourceKey="AddTestTaskMenuItem"/>
                        <StaticResource ResourceKey="AddBugMenuItem"/>
                        <StaticResource ResourceKey="AddAfterDeployBugMenuItem"/>
                        <Separator/>
                        <StaticResource ResourceKey="AddImpedimentMenuItem"/>
                    </ContextMenu.Items>                    
                </ContextMenu>
            </ListBox.ContextMenu>




        </ListBox>
        <StackPanel Grid.Row="0"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Top"
                    Height="20"
                    Orientation="Horizontal"
                    FlowDirection="RightToLeft"
                    >
            <TextBlock FontSize="8pt" Margin="5,0,5,0" Foreground="Gray" FlowDirection="LeftToRight">
                <TextBlock.Text>
                    <Binding ElementName="postItListBoxControl" Path="TaskHourCount" StringFormat="{x:Static props:Resources.N_hrs}" />
                </TextBlock.Text>
            </TextBlock>
            <TextBlock FontSize="8pt"  Margin="5,0,5,0" Foreground="Gray" FlowDirection="LeftToRight">
                <TextBlock.Text>
                    <Binding ElementName="postItListBoxControl" Path="TaskCount" StringFormat="{x:Static props:Resources.N_tasks}" />
                </TextBlock.Text>
            </TextBlock>

        </StackPanel>
    </Grid>





</BadHabit_Factory_Controls:TaskViewerBase>
